//
//  HomeViewController.m
//  momo
//
//  Created by HappyMilk 02 on 2017/5/1.
//  Copyright © 2017年 tomi. All rights reserved.
//

#import "HomeViewController.h"
#import "PublicTool.h"
#import "UserModel.h"
#import "UIImageView+WebCache.h"
#import "SendViewController.h"
#import "LoginHeader.h"
#import "evelModel.h"

@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *imgv_head;
@property (weak, nonatomic) IBOutlet UILabel *lab_name;
@property (weak, nonatomic) IBOutlet UILabel *lab_address;
@property (weak, nonatomic) IBOutlet UILabel *lab_emotional;
@property (weak, nonatomic) IBOutlet UILabel *lab_number;
@property (weak, nonatomic) IBOutlet UITableView *tabview;
@property (weak, nonatomic) IBOutlet UIView *view_home;

@property (weak, nonatomic) IBOutlet UILabel *lab_message;



@property (nonatomic, strong) NSMutableArray *evelArr;


@end

@implementation HomeViewController

- (IBAction)jubao:(UIButton *)sender {
    
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Report" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Vulgar",@"Porn",@"Political",@"Fraud", nil];
    [sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
   
    if (buttonIndex == 4) {
        
    }else{
        SHOW_HUD_MESSAGE(@"Report success !")
    }
}

- (IBAction)replyAction:(UIButton *)sender {
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    SendViewController *vc = [sb instantiateViewControllerWithIdentifier:@"SendViewController"];
    vc.is_reply = YES;
    vc.user_name = _lab_name.text;
    vc.msg_id = _msg_id;
    vc.msg_user_id = _msg_user_id;
    [self presentViewController:vc animated:YES completion:nil];
}
- (void)viewWillAppear:(BOOL)animated{
    
    [self getEvelMessages];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [evelModel registerSubclass];
    _evelArr = [NSMutableArray array];
    _view_home.layer.masksToBounds = YES;
    _view_home.layer.cornerRadius = 15;
    
    [self getUserInfometion];
    
    
    
}
- (void)getEvelMessages{
    AVQuery *query = [AVQuery queryWithClassName:@"Evel_list"];
    [query whereKey:@"msg_id" equalTo:_msg_id];
    [query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        if (objects.count>0) {
            _evelArr = [objects mutableCopy];
            _lab_number.text = [NSString stringWithFormat:@"Reply(%ld)",_evelArr.count];
            [self.tabview reloadData];
        }else{
            _lab_number.text = @"Reply(0)";
        }
    }];
}
- (void)getUserInfometion{
    
    AVQuery *query = [AVQuery queryWithClassName:@"User_list"];
    [query whereKey:@"user_id" equalTo:_msg_user_id];
    [query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        if (objects.count>0) {
            UserModel *model = [objects firstObject];
            [_imgv_head sd_setImageWithURL:[NSURL URLWithString:model.user_img.url]];
            _lab_name.text = model.user_name;
            _lab_address.text = model.user_address;
            _lab_emotional.text = model.user_emotion;
            _lab_message.text = _message;
        }
    }];
}


- (IBAction)dismissvc:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _evelArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    evelModel *model = _evelArr[indexPath.row];
    static NSString *cellid = @"qwe";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] init];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@: %@",model.ev_name,model.ev_contents];
    cell.textLabel.font = [UIFont systemFontOfSize:12];
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
